57
Example A: Main() functions
Rectangle: Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
int main()
{
Computer compute; //To create an 'instance' of the
// class, simply treat it like you would a structure. (An
// instance is simply when you create an actual object from
// the class, as opposed to having the definition of the class)
compute.setspeed(100); //To call functions in the class,
// you put the name of the instance, a period, and then the
// function name.
cout<<compute.readspeed(); //See above note.
return 0;
}
This concept makes easy to prevent variables that are contained (or owned) by the class being overwritten accidentally. It also allows a totally different way of thinking about programming.